package simply.learn.hibernate.learn.example1;

import java.io.File;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class SingletonSessionFactory {

	private static SessionFactory sessionFactory;
	
	private SingletonSessionFactory() {
		File configurationFile = new File(this.getClass().getResource("/hibernate-example1.cfg.xml").getPath());
		Configuration configuration = new Configuration().configure(configurationFile);
		sessionFactory = configuration.buildSessionFactory();
	}
	
	public static SessionFactory getSessionFactory(){
		if(sessionFactory==null){
			new SingletonSessionFactory();
		}
		return sessionFactory;
	}
}
